const sidebarCommon = {
    mainTabs: [],
    mainTabsActiveName: '',
    menuActiveName: ''
}

export function remove(array, matchName) {
    for (let i = 0; i < array.length; i++) {
        if (array[i].name === matchName) {
            array.splice(i, 1);
            break;
        }
    }
    return array;
}

export function routeHandle(route) {
    //每次切换页面，重新计算页面高度和内容区高度
    let mainTabs = sidebarCommon.mainTabs;

    if (route.meta.isTab) {
        // tab选中, 不存在先添加
        let tab = mainTabs.filter(item => item.name === route.name)[0];
        // console.log("选择: " + JSON.stringify(tab));
        if (!tab) {
            tab = {
                menuId: route.meta.menuId || route.name,
                name: route.name,
                path: route.path,
                title: route.meta.title,
                iframeUrl: route.meta.iframeUrl || '',
                params: route.params,
                query: route.query
            };
            sidebarCommon.mainTabs = mainTabs.concat(tab);
            // console.log("定义: " + JSON.stringify(tab));
            // console.log("内容: " + JSON.stringify(sidebarCommon.mainTabs));
        }
        sidebarCommon.menuActiveName = tab.menuId + '';
        sidebarCommon.mainTabsActiveName = tab.name;

        // console.log("id: " + sidebarCommon.menuActiveName);
        // console.log("tab name: " + sidebarCommon.mainTabsActiveName);
    }
}
export {sidebarCommon}
